public Image arithmetic(Image im1, Image im2, int width, int height, int op,
                                boolean r, boolean g, boolean b, boolean clip)
    {
        /* im1 = source image 1.
           im2 = source image 2.
           width  = width of images (they are the same size)
           height = height of images
           op     = operation.  See top of class for definitions.
                    NOTE: In subtraction, the result is im1 - im2.
                    in Division, the result is im1/im2.
           r, g, b = affected channels
           clip    =            X < 0           X > 255
                                -------------------------
                        true	X = 0	        X = 255
                        false	X = 256 +X	    X = X -256
        */

        int pix1[] = JIPTUtilities.getPixelArray(im1);
        int pix2[] = JIPTUtilities.getPixelArray(im2);

        // Get the sizes. Size1 and Size2 SHOULD BE the same, but this will catch Array exceptions
        // in case on is slightly longer than another.
        int size1 = pix1.length;
        int size2 = pix2.length;
        int size  = 0;
        if(size1 > size2)
            size = size2;
        else
            size = size1;
        int new_pix[] = new int[size];

        /////////////////////////////////////////
        ////////////// Main Loop ////////////////
        /////////////////////////////////////////
        for(int i = 0; i < size; i++)
        {
            /////////////////
            /// Source 1 ////
            /////////////////
            int alpha1 = (pix1[i] >> 24) & 0xff;
	        int red1   = (pix1[i] >> 16) & 0xff;
	        int green1 = (pix1[i] >>  8) & 0xff;
	        int blue1  = (pix1[i]      ) & 0xff;

            /////////////////
            /// Source 2 ////
            /////////////////
            int alpha2 = (pix2[i] >> 24) & 0xff;
	        int red2   = (pix2[i] >> 16) & 0xff;
	        int green2 = (pix2[i] >>  8) & 0xff;
	        int blue2  = (pix2[i]      ) & 0xff;

            /////////////////
            /// Result   ////
            /////////////////
            int alpha3 = 255;
            int red3   = 0;
            int green3 = 0;
            int blue3  = 0;

            if(r)
                red3   = performOperation(red1, red2, op, clip);
            if(g)
                green3 = performOperation(green1, green2, op, clip);
            if(b)
                blue3  = performOperation(blue1, blue2, op, clip);

            new_pix[i] = 0;
    		new_pix[i] += (alpha3         << 24);   // alpha
    		new_pix[i] += (red3           << 16);   // r
    		new_pix[i] += (green3         <<  8);   // g
    		new_pix[i] += (blue3               );   // b

        }


        Image new_im = Toolkit.getDefaultToolkit().createImage(new MemoryImageSource(width, height, new_pix, 0, width));
        return new_im;
    }