ColorSeparation.java


Below is the syntax highlighted version of ColorSeparation.java.


/*************************************************************************
 *  Compilation:  javac ColorSeparation.java
 *  Execution:    java ColorSeparation filename
 *  Dependencies: Picture.java
 *  Reads in an image from a file, and displays the red, green, and
 *  blue portions in three separate windows.   Booksite Creative Ex 3.1.60
 *************************************************************************/

import java.awt.Color;

public class ColorSeparation {
   public static void main(String[] args) {
      // read in the picture specified by command-line argument
      Picture pic = new Picture(args[0]);
      int width  = pic.width();
      int height = pic.height();

      // create three empty pictures of the same dimension
      Picture R = new Picture(width, height);
      Picture G = 
      Picture B = 

      // separate colors
      for (int x = 0; x < width; x++) {
         for (int y = 0; y < height; y++) {
            Color c = pic.                             // color value of
                                                       // current pixel
            int r = c.getRed();
            int g = 
            int b = 

            R.set(x, y, new Color(r, 0, 0));
            G
            B
         }
      }

      // display each one in its own window
      R.show();



   }  
}