 /*
 * @(#) BrightnessFilter.java 1.0 99/10/4
 * Copyright (c) 1999 Larry Rodrigues
 */
   import java.awt.*;
   import java.awt.event.*;
   import java.awt.image.*;
   import java.io.*;
   public class BrightnessFilter extends RGBImageFilter  {
      float brfactor = (float)1.0;
      
      public BrightnessFilter(int br) {
         canFilterIndexColorModel = true;
         brfactor *= br/(float)50;
      }

      public int  filterRGB (int x, int y, int rgb){
         int a = rgb & 0xff000000;
         int r = rgb & 0xff0000 >>16;
         int g = rgb & 0xff00 >>8;
         int b = rgb & 0xff;
         
         float[] hsbvalues = {(float)0.0, (float)0.0, (float)0.0};

         float[] hs = Color.RGBtoHSB(r,g,b, hsbvalues);
         float bright = hsbvalues[2];
         bright = bright * (float)brfactor ;
         bright = (bright>1.0) ? (float) 1.0 : bright ;
         int col = Color.HSBtoRGB(hsbvalues[0],hsbvalues[1],bright);
         int rgbx = col & 0xffffff;
         return a|rgbx;
      } 
   }
