Coverage Report - org.dishevelled.iconbundle.impl.SelectionRasterOp
 
Classes in this File Line Coverage Branch Coverage Complexity
SelectionRasterOp
100%
14/14
83%
5/6
2.5
 
 1  
 /*
 2  
 
 3  
     dsh-iconbundle  Bundles of variants for icon images.
 4  
     Copyright (c) 2003-2011 held jointly by the individual authors.
 5  
 
 6  
     This library is free software; you can redistribute it and/or modify it
 7  
     under the terms of the GNU Lesser General Public License as published
 8  
     by the Free Software Foundation; either version 3 of the License, or (at
 9  
     your option) any later version.
 10  
 
 11  
     This library is distributed in the hope that it will be useful, but WITHOUT
 12  
     ANY WARRANTY; with out even the implied warranty of MERCHANTABILITY or
 13  
     FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
 14  
     License for more details.
 15  
 
 16  
     You should have received a copy of the GNU Lesser General Public License
 17  
     along with this library;  if not, write to the Free Software Foundation,
 18  
     Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307  USA.
 19  
 
 20  
     > http://www.fsf.org/licensing/licenses/lgpl.html
 21  
     > http://www.opensource.org/licenses/lgpl-license.php
 22  
 
 23  
 */
 24  
 package org.dishevelled.iconbundle.impl;
 25  
 
 26  
 import java.awt.Color;
 27  
 
 28  
 import java.awt.image.Raster;
 29  
 import java.awt.image.WritableRaster;
 30  
 
 31  
 /**
 32  
  * Selection RasterOp.
 33  
  *
 34  
  * @author  Michael Heuer
 35  
  * @version $Revision: 974 $ $Date: 2011-01-04 21:40:23 -0600 (Tue, 04 Jan 2011) $
 36  
  */
 37  
 final class SelectionRasterOp
 38  
     extends AbstractRasterOp
 39  
 {
 40  
     /** Pixel array size. */
 41  
     private static final int PIXEL_ARRAY_SIZE = 4;
 42  
 
 43  
     /** White color component. */
 44  
     private static final int WHITE = 255;
 45  
 
 46  
     /** Selection color. */
 47  
     private final Color selectionColor;
 48  
 
 49  
 
 50  
     /**
 51  
      * Create a new selection RasterOp with the specified
 52  
      * selection color.
 53  
      *
 54  
      * @param selectionColor selection color
 55  
      */
 56  
     public SelectionRasterOp(final Color selectionColor)
 57  1820
     {
 58  1820
         this.selectionColor = selectionColor;
 59  1820
     }
 60  
 
 61  
 
 62  
     /** {@inheritDoc} */
 63  
     public WritableRaster filter(final Raster src, final WritableRaster dest)
 64  
     {
 65  1820
         if (selectionColor != null)
 66  
         {
 67  1820
             float[] pixel = new float[PIXEL_ARRAY_SIZE];
 68  1820
             float[] selection = selectionColor.getColorComponents(new float[PIXEL_ARRAY_SIZE]);
 69  
 
 70  109720
             for (int x = 0, w = src.getWidth(); x < w; x++)
 71  
             {
 72  9124440
                 for (int y = 0, h = src.getHeight(); y < h; y++)
 73  
                 {
 74  9016540
                     pixel = src.getPixel(x, y, pixel);
 75  9016540
                     pixel[0] = Math.min(pixel[0], selection[0] * WHITE);
 76  9016540
                     pixel[1] = Math.min(pixel[1], selection[1] * WHITE);
 77  9016540
                     pixel[2] = Math.min(pixel[2], selection[2] * WHITE);
 78  
 
 79  9016540
                     dest.setPixel(x, y, pixel);
 80  
                 }
 81  
             }
 82  
         }
 83  1820
         return dest;
 84  
     }
 85  
 }