/***
 * Image/J Plugins
 * Copyright (C) 2002-2005 Jarek Sacha
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 *
 * Latest release available at http://sourceforge.net/projects/ij-plugins/
 */
package net.sf.ij_plugins.color;

import ij.process.ByteProcessor;
import ij.process.ColorProcessor;

/**
 * <p/>
 * Created Apr 5, 2005 9:20:35 PM.
 *
 * @author Jarek Sacha
 * @version $Revision: 1.1 $
 */
public class ColorProcessorUtils {
    private ColorProcessorUtils() {
    }

    /**
     * Splits ColorProcessor into ByteProcessors representing each of three bands (red, gree, and
     * blue).
     *
     * @param cp
     * @return
     * @see #mergeRGB(ij.process.ByteProcessor[])
     */
    static public ByteProcessor[] splitRGB(final ColorProcessor cp) {
        final int width = cp.getWidth();
        final int height = cp.getHeight();

        final ByteProcessor redBp = new ByteProcessor(width, height);
        final ByteProcessor greenBp = new ByteProcessor(width, height);
        final ByteProcessor blueBp = new ByteProcessor(width, height);

        final byte[] redPixels = (byte[]) redBp.getPixels();
        final byte[] greenPixels = (byte[]) greenBp.getPixels();
        final byte[] bluePixels = (byte[]) blueBp.getPixels();

        cp.getRGB(redPixels, greenPixels, bluePixels);

        return new ByteProcessor[]{redBp, greenBp, blueBp};
    }

    /**
     * Merges RGB bands into a ColorProcessor.
     *
     * @param bps
     * @return
     */
    static public ColorProcessor mergeRGB(final ByteProcessor[] bps) {

        if (bps == null) {
            throw new IllegalArgumentException("Argument 'bps' cannot be null.");
        }
        if (bps.length != 3) {
            throw new IllegalArgumentException("Size of array 'bps' has to equal 3, got "
                    + bps.length + ".");
        }

        final int width = bps[0].getWidth();
        final int height = bps[0].getHeight();

        if (!(width == bps[1].getWidth() && height == bps[1].getHeight()
                && width == bps[2].getWidth() && height == bps[2].getHeight())) {
            throw new IllegalArgumentException("All imput processor have to be of the same size.");
        }

        byte [][] pixels = new byte[3][];
        for (int i = 0; i < bps.length; i++) {
            pixels[i] = (byte[]) bps[i].getPixels();
        }

        ColorProcessor dest = new ColorProcessor(width, height);

        dest.setRGB(pixels[0], pixels[1], pixels[2]);

        return dest;
    }
}

@@ -1,12 +1,10 @@
 /*
-**
 %0A * Imag
@@ -40,17 +40,17 @@
 2002-200
-5
+8
  Jarek S
@@ -871,16 +871,19 @@
 lugins/%0A
+ *%0A
  */%0Apack
@@ -996,43 +996,8 @@
 p/%3E%0A
- * Created Apr 5, 2005 9:20:35 PM.%0A
  *%0A 
@@ -1047,16 +1047,49 @@
 : 1.1 $%0A
+ * @since Apr 5, 2005 9:20:35 PM%0A
  */%0Apubl
@@ -1267,23 +1267,16 @@
 ree, and
-%0A     *
  blue).%0A
@@ -1298,31 +1298,82 @@
 param cp
-%0A     * @return
+ input color processor%0A     * @return ByteProcessor for each band.
 %0A     * 
@@ -2184,16 +2184,61 @@
 aram bps
+ ByteProcessor for red, green, and blue band.
 %0A     * 
@@ -2244,16 +2244,29 @@
  @return
+ merged bands
 %0A     */
@@ -3001,17 +3001,16 @@
     byte
- 
 %5B%5D%5B%5D pix

Correct javadoc.