/**
   * Writes a ColorImage to a file byteSizing first
   *
   * @param im the ColorImage
   */
  public void writeByteSized(ColorImage im) throws IOException {

    X = im.X();
    Y = im.Y();
    int[] color = new int[3];

    // convert to byte size
    ColorImage tmpim = (ColorImage) im.copy();
    tmpim.byteSize();

    // write PPM in raw format

    writeRawPPMHeader(X, Y);
    for (int y = 0; y < Y; y++) {
      for (int x = 0; x < X; x++) {
        color = tmpim.get(x, y);
        data.write((byte) color[0]);
        data.write((byte) color[1]);
        data.write((byte) color[2]);
      }
    }
  }
 /**
  * Scales the range of <code>image</code> to an arbitrary min/max. The range used for all planes
  * is the global max, min of the image.
  *
  * @param image ColorImage to scale.
  * @return <code>image</code>.
  */
 protected Image apply(ColorImage image) {
   return apply(image, new ROI(0, 0, image.X() - 1, image.Y() - 1));
 }