Coverage Report - net.wotonomy.ui.swing.components.TintedImageFilter
 
Classes in this File Line Coverage Branch Coverage Complexity
TintedImageFilter
0% 
0% 
4.333
 
 1  
 /*
 2  
 Wotonomy: OpenStep design patterns for pure Java applications.
 3  
 Copyright (C) 2001 Intersect Software Corporation
 4  
 
 5  
 This library is free software; you can redistribute it and/or
 6  
 modify it under the terms of the GNU Lesser General Public
 7  
 License as published by the Free Software Foundation; either
 8  
 version 2.1 of the License, or (at your option) any later version.
 9  
 
 10  
 This library is distributed in the hope that it will be useful,
 11  
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 12  
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 13  
 Lesser General Public License for more details.
 14  
 
 15  
 You should have received a copy of the GNU Lesser General Public
 16  
 License along with this library; if not, see http://www.gnu.org
 17  
 */
 18  
 
 19  
 package net.wotonomy.ui.swing.components;
 20  
 
 21  
 import java.awt.Color;
 22  
 import java.awt.image.RGBImageFilter;
 23  
 
 24  
 /**
 25  
  * TintedImageFilter tints all gray pixels half-way towards
 26  
  * the value passed into the constructor.  This "tints" a
 27  
  * mostly grayscale image.  This has proven useful for tinting
 28  
  * user interface decorative images towards one of the SystemColor 
 29  
  * constants to better mesh with a platform look and feel.
 30  
  *
 31  
  * @author michael@mpowers.net
 32  
  * @author $Author: cgruber $
 33  
  * @version $Revision: 893 $
 34  
  */
 35  
     public class TintedImageFilter extends RGBImageFilter
 36  
     {
 37  
         double redOffset, greenOffset, blueOffset;
 38  
         
 39  0
             public TintedImageFilter( Color aColor ) 
 40  0
         {
 41  0
                     canFilterIndexColorModel = true;
 42  0
             redOffset = getOffset( aColor.getRed() );
 43  0
             greenOffset = getOffset( aColor.getGreen() );
 44  0
             blueOffset = getOffset( aColor.getBlue() );
 45  0
             }
 46  
         
 47  
         /**
 48  
         * Calculates the offset used to modify color 
 49  
         * values.  This method returns half the difference
 50  
         * between the specified color level and 192.
 51  
         */
 52  
         protected double getOffset( int colorValue )
 53  
         {
 54  0
             return ( colorValue - 192 ) / 2;   
 55  
         }
 56  
 
 57  
             public int filterRGB(int x, int y, int rgb) 
 58  
         {
 59  
 
 60  0
             int red   = ( rgb & 0xff0000 ) >> 16;
 61  0
             int green = ( rgb & 0x00ff00 ) >> 8;
 62  0
             int blue  = ( rgb & 0x0000ff );
 63  
             
 64  
             // if roughly black
 65  0
             if ( red + green + blue < 30 ) return rgb;
 66  
             
 67  
             // if roughly gray
 68  0
             if ( ( Math.abs( red - green ) < 10 ) 
 69  0
             && ( Math.abs( red - blue ) < 10 ) )
 70  
             {
 71  0
                 red += redOffset;
 72  0
                 if ( red < 0 ) red = 0; 
 73  0
                 if ( red > 255 ) red = 255;
 74  0
                 green += greenOffset;
 75  0
                 if ( green < 0 ) green = 0; 
 76  0
                 if ( green > 255 ) green = 255;
 77  0
                 blue += blueOffset;
 78  0
                 if ( blue < 0 ) blue = 0; 
 79  0
                 if ( blue > 255 ) blue = 255;
 80  
                 
 81  0
                 return new Color( red, green, blue ).getRGB();                
 82  
             }
 83  
             
 84  0
             return rgb;
 85  
         }            
 86  
     }
 87  
     
 88  
 /*
 89  
  * $Log$
 90  
  * Revision 1.1  2006/02/16 13:22:22  cgruber
 91  
  * Check in all sources in eclipse-friendly maven-enabled packages.
 92  
  *
 93  
  * Revision 1.2  2001/01/18 21:27:04  mpowers
 94  
  * Made the tinting a little darker.
 95  
  *
 96  
  * Revision 1.1  2001/01/12 17:36:27  mpowers
 97  
  * Contributing TintedImageFilter.
 98  
  *
 99  
  *
 100  
  */