public Image hsi_adjust(Image im, int width, int height, int hue, int saturation, int brightness)
    {
        // The hue, saturation, and brightness variables represent values in the range
        // from -100 to 100.  -100 is a full decrease in value, 0 is no change, and 100 is a full
        // increase.
        // NOTE: Brightness is the same as Intensity.  I use "brightness" to be consistent
        //       with the Color class's terminology.



        int pix[] = JIPTUtilities.getPixelArray(im);
        int new_pix[] = new int[width*height];

        for(int i = 0; i < pix.length; i++)
        {
            //////// Get pixels ///////////////////
            int alpha = (pix[i] >> 24) & 0xff;
	        int red   = (pix[i] >> 16) & 0xff;
	        int green = (pix[i] >>  8) & 0xff;
	        int blue  = (pix[i]      ) & 0xff;

            // Get HSB for this pixel
            float hsb_array[] = Color.RGBtoHSB(red, green, blue, null);

            /////////////////////////////
            /// Get new HSB values //////
            /////////////////////////////

            ///////////////////
            ///// Hue /////////
            ///////////////////
            float degree_hue = hsb_array[0]*360.0f;

            degree_hue = degree_hue + (hue*360.0f/100.0f);

            if(degree_hue > 360.0f)
                degree_hue = degree_hue - 360.0f;
            else if(degree_hue < 0.0f)
                degree_hue = degree_hue + 360;


            hsb_array[0] = degree_hue/360.0f;

            ////////////////////////
            ///// Saturation ///////
            ////////////////////////



            if(saturation <= 0)
                hsb_array[1] = hsb_array[1] + saturation*hsb_array[1]/100.0f;
            else
                hsb_array[1] = hsb_array[1] + saturation*(hsb_array[1])/100.0f;

           // hsb_array[1] = 1;
            ////////////////////////
            //// Put in range //////
            ////////////////////////
            if(hsb_array[0] > 1)
                hsb_array[0] = 1;

            if(hsb_array[1] > 1)
                hsb_array[1] = 1;

            if(hsb_array[2] > 1)
                hsb_array[2] = 1;

           //System.out.println("HSI = " + hsb_array[0] + " " + hsb_array[1] + " " + hsb_array[2]);
            Color new_color = new Color(Color.HSBtoRGB(hsb_array[0], hsb_array[1], hsb_array[2]));

            red = new_color.getRed();
            green = new_color.getGreen();
            blue = new_color.getBlue();

            ////////////////////////////////////////
            //// Adjust brightness in RGB domain ///
            ///////////////////////////////////////
            red   = red   + (int) ((brightness/100.0)*255);
            green = green + (int) ((brightness/100.0)*255);
            blue  = blue  + (int) ((brightness/100.0)*255);

            ///// Put in correct range (0...255) /////
            red   = putInRange(red);
            green = putInRange(green);
            blue  = putInRange(blue);

            /////////////////////////////////////////////
            ///////////// Put in new pixel array ////////
            /////////////////////////////////////////////
            new_pix[i] = 0;
    		new_pix[i] += (alpha         << 24);   // alpha
    		new_pix[i] += (red           << 16);   // r
    		new_pix[i] += (green         <<  8);   // g
    		new_pix[i] += (blue               );   // b


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